#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>

int GetDirnums(char* path){
    int size=0;
    DIR *p=opendir(path);
    struct dirent *pdir=readdir(p);
    while(1){
        if(pdir==NULL){
            return size;
        }
        if(pdir->d_type==DT_REG&&strcmp(pdir->d_name,"1.txt")==0){
            char buf[300]={0};
            sprintf(buf,"%s/%s",path,pdir->d_name);
            struct stat st;
            stat(buf,&st);
            size+=st.st_size;
        }
        if(pdir->d_type==DT_DIR && strcmp(pdir->d_name,".")!=0
           &&strcmp(pdir->d_name,".")!=0){
            size++;
            char buf[300]={0};
            sprintf(buf,"%s/%s",path,pdir->d_name);
            int sonsize= GetDirnums(buf);
            size +=sonsize;
        }

    }
    return 0;
}

int main(){
    int size=GetDirnums("./test");
    printf("1.txtsumsize: %d\n",size);
    return 0;
}


